package com.pl.dailycollection.study.lock;

import java.util.concurrent.locks.Condition;
import java.util.concurrent.locks.ReentrantLock;

/**
 * @ClassName SynchronizedTest
 * @Description: 通过synchronized实现库存增减
 * @Author pl
 * @Date 2019/12/31
 * @Version V1.0
 **/
public class InventoryBySynchronized {
    //库存量
    private int count=0;
    //最大促存量
    private int MAX_COUNT= 10;

    public synchronized void add() throws InterruptedException {
        while (count>=MAX_COUNT)
            wait();
        count++;
        notifyAll();
    }

    public void remove() throws InterruptedException {
        while (count<=MAX_COUNT)
            wait();
        count--;
        notifyAll();
    }
}
